<template>
  <div class="app-container">
    <el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="入仓类型" prop="inOrderType">
            <el-select v-model="form.inOrderType" v-if="editAble" placeholder="出入仓类型" disabled>
              <el-option
                v-for="dict in inout_storehouse"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
            <dict-tag v-else :options="inout_storehouse" :value="form.inOrderType" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="入仓单编号" prop="inOrderCode">
            <code-input
              v-if="editAble"
              v-model="form.inOrderCode"
              code="IN_HOUSE_CODE"
              :disabled="!!form.id"
              placeholder="请输入入仓单编号"
            />
            <el-tooltip v-else effect="dark" :content="form.inOrderCode">
              <div class="form-text">{{ form.inOrderCode }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="入仓单名称" prop="inOrderName">
            <el-input v-if="editAble" v-model="form.inOrderName" placeholder="请输入入仓单名称" />
            <el-tooltip v-else effect="dark" :content="form.inOrderName">
              <div class="form-text">{{ form.inOrderName }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="ERP出库单号" prop="vbillCode">
            <el-input v-if="editAble" v-model="form.vbillCode" placeholder="请输入ERP出库单号" />
            <el-tooltip v-else effect="dark" :content="form.vbillCode">
              <div class="form-text">{{ form.vbillCode }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <SearchTool
          v-if="editAble"
          :disabled='operationTitle.indexOf("编辑")>-1'
          :code="{
            factory: 'factoryCode',
            workshop: 'workshopCode',
            line: 'lineCode',
            section: 'sectionCode',
          }"
          :titles="{
            factory: '工厂',
            workshop: '工段',
            line: '产线',
            section: '工艺段',
          }"
          :layout="true"
          :span="6"
          v-model:factory="form.factoryCode"
          v-model:workshop="form.workshopCode"
          v-model:line="form.lineCode"
          v-model:section="form.sectionCode"
          @factoryChange="toolChange"
          @workshopChange="toolChange"
          @lineChange="toolChange"
          @sectionChange="toolChange"
        ></SearchTool>
        <el-col v-if="!editAble" :span="6">
          <el-form-item label="工厂" prop="factoryCode">
            <div class="form-text">{{ form.factoryName }}</div>
          </el-form-item>
        </el-col>
        <el-col v-if="!editAble" :span="6">
          <el-form-item label="工段" prop="workshopCode">
            <div class="form-text">{{ form.workShopName }}</div>
          </el-form-item>
        </el-col>
        <el-col v-if="!editAble" :span="6">
          <el-form-item label="产线" prop="lineCode">
            <div class="form-text">{{ form.lineName }}</div>
          </el-form-item>
        </el-col>
        <el-col v-if="!editAble" :span="6">
          <el-form-item label="工艺段" prop="sectionCode">
            <div class="form-text">{{ form.sectionName }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="来料时间" prop="comeTime">
            <el-date-picker
              v-if="editAble"
              v-model="form.comeTime"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
              style="width: 100%"
              placeholder="请选择来料时间"
            />
            <el-tooltip v-else effect="dark" :content="form.comeTime">
              <div class="form-text">{{ form.comeTime }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="送料人" prop="deliveryPerson">
            <UserSelect
              v-if="editAble"
              v-model="form.deliveryPersonName"
              v-model:code="form.deliveryPerson"
              placeholder="请选择送料人"
              title="选择送料人"
            ></UserSelect>
            <el-tooltip v-else effect="dark" :content="form.deliveryPersonName">
              <div class="form-text">{{ form.deliveryPersonName }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col v-if="operationTitle === '确认入仓' || operationTitle === '物料入仓详情'" :span="6">
          <el-form-item
            label="入仓时间"
            :rules="
              operationTitle == '确认入仓' && [
                {
                  required: true,
                  message: '请选择入仓时间',
                  trigger: 'blur',
                },
              ]
            "
            prop="inTime"
          >
            <el-date-picker
              v-if="operationTitle === '确认入仓'"
              v-model="form.inTime"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
              style="width: 100%"
              placeholder="请选择来料时间"
            />
            <el-tooltip v-else effect="dark" :content="form.inTime">
              <div class="form-text">{{ form.inTime }}</div>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注" prop="remark">
            <el-input
              v-if="editAble"
              v-model="form.remark"
              type="textarea"
              :maxlength="200"
              show-word-limit
              placeholder="请输入内容"
            />
            <div v-else class="form-text">{{ form.remark }}</div>
          </el-form-item>
        </el-col>
        <el-col v-if="form.status == 'entered_warehouse'" :span="6">
          <el-form-item label="确认入仓人" prop="inWarehouseName">
            <div class="form-text">{{ form.inWarehouseName }}</div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-tabs v-model="activeName" class="demo-tabs">
      <el-tab-pane label="入仓明细" name="first">
        <!-- v-hasPermi="['warehouse:WhStorehouseInDetail:list']" -->
        <el-form
          v-show="operationTitle == '确认入仓' || operationTitle == '物料入仓详情'"
          :model="searchParams"
          ref="queryRef"
          :inline="true"
          label-width="100px"
          class="form-search"
        >
          <el-form-item label="ERP订单编号" prop="orderCode">
            <el-input
              v-model="searchParams.orderCode"
              placeholder="请输入ERP订单编号"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
            <el-input
              v-model="searchParams.productName"
              placeholder="请输入产品名称"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="物料名称" prop="matName">
            <el-input
              v-model="searchParams.matName"
              placeholder="请输入物料名称"
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="search" @click="handleQuery">查询</el-button>
            <el-button icon="refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <!-- v-hasPermi="['warehouse:inStorehouse:select']" -->
        <el-row :gutter="10" class="mb8">
          <el-col v-if="editAble" :span="1.5">
            <el-button type="primary" icon="plus" @click="handleAddWhStorehouseInDetail">
              选择物料
            </el-button>
          </el-col>
          <el-col v-if="binEditAble" :span="1.5" class="top-right-btn">
            <el-button type="primary" link @click="batchSetting">批量设置线边仓、库位</el-button>
          </el-col>
        </el-row>
        <!-- v-hasPermi="['warehouse:WhStorehouseInDetail:list']" -->
        <el-form
          ref="tableForm"
          :model="whStorehouseInDetailList"
          label-width="0"
        >
          <el-table
            :data="whStorehouseInDetailList"
            :row-class-name="rowWhStorehouseInDetailIndex"
            border
            maxHeight="400"
            show-overflow-tooltip
            ref="whStorehouseInDetail"
          >
            <el-table-column label="序号" align="center" prop="index" width="80" />
            <el-table-column label="ERP订单编号" prop="orderCode" min-width="150"></el-table-column>
            <el-table-column label="产品名称" prop="productName" min-width="150"></el-table-column>
            <el-table-column label="产品编号" prop="productCode" width="150"></el-table-column>
            <el-table-column label="物料编号" prop="matCode" width="150"></el-table-column>
            <el-table-column label="物料名称" prop="matName" width="150"></el-table-column>
            <el-table-column label="来料数量" prop="receiveNumber" width="150">
              <template v-if="editAble" #header>
                <span style="color: red">*</span>
                <span>来料数量</span>
              </template>
              <template v-if="editAble" #default="scope">
                <el-form-item
                  label=""
                  :prop="`[${scope.$index}].receiveNumber`"
                  :rules="[
                    {
                      required: true,
                      message: '请输入数量',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input-number
                    v-model="scope.row.receiveNumber"
                    @change="handleInputChange($event, scope, 'receiveNumber')"
                    controls-position="right"
                  ></el-input-number>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="单位" prop="unit" width="150"></el-table-column>
            <!-- <el-table-column label="规格" prop="spec" width="150"></el-table-column> -->

            <el-table-column label="批次号" prop="batchNo" width="150">
              <template v-if="editAble" #header>
                <span style="color: red">*</span>
                <span>批次号</span>
              </template>
              <template v-if="editAble" #default="scope">
                <el-form-item
                  label=""
                  :prop="`[${scope.$index}].batchNo`"
                  :rules="[
                    {
                      required: true,
                      message: '请输入批次号',
                      trigger: 'blur',
                    },
                  ]"
                >
                  <el-input
                    v-model="scope.row.batchNo"
                    @change="handleInputChange($event, scope, 'batchNo')"
                    placeholder="请输入批次号"
                  />
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="线边仓" prop="storehouseName" width="150">
              <template v-if="binEditAble" #header>
                <span style="color: red">*</span>
                <span>线边仓</span>
              </template>
              <template v-if="binEditAble" #default="scope">
                <el-form-item
                  label=""
                  :prop="`[${scope.$index}].storehouseCode`"
                  :rules="[
                    {
                      required: true,
                      message: '请选择线边仓',
                      trigger: ['blur', 'change'],
                    },
                  ]"
                >
                  <StoreSelect
                    v-model="scope.row.storehouseCode"
                    v-model:name="scope.row.storehouseName"
                    :line="form.lineCode"
                    :section="form.sectionCode"
                    :autoSelect="operationTitle === '确认入仓'"
                    :customOptions="storehouseList"
                    placeholder="请选择线边仓"
                    @change="tableStoreChange($event, scope)"
                  ></StoreSelect>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="库位" prop="binName" width="150">
              <template v-if="binEditAble" #header>
                <span style="color: red">*</span>
                <span>库位</span>
              </template>
              <template v-if="binEditAble" #default="scope">
                <el-form-item
                  label=""
                  :prop="`[${scope.$index}].binCode`"
                  :rules="[
                    {
                      required: true,
                      message: '请选择库位',
                      trigger: ['blur', 'change'],
                    },
                  ]"
                >
                  <BinSelect
                    v-model="scope.row.binCode"
                    :key="`bin-${scope.$index}`"
                    :autoSelect="operationTitle === '确认入仓'"
                    :parent="scope.row.storehouseCode"
                    @change="handleInputChange($event, scope, 'binCode')"
                    placeholder="请选择库位"
                  ></BinSelect>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column
              v-if="editAble"
              label="操作"
              align="center"
              fixed="right"
              minWidth="100"
              class-name="small-padding fixed-width"
            >
              <template #default="scope">
                <el-button
                  link
                  icon="delete"
                  type="primary"
                  @click="handleDeleteWhStorehouseInDetail(scope.row, scope.$index)"
                  v-hasPermi="['warehouse:inStorehouse:remove']"
                >
                  移除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <matDialog
      v-model="show"
      :workshop="form.workshopCode"
      :orderCode="form.erpOrderCode"
      :chioseList='chioseList'
      @change="handleChange"
    ></matDialog>
    <el-dialog
      title="批量设置线边仓、库位"
      v-model="showSetting"
      width="700px"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form ref="settingDialog" :model="settingForm" :rules="settingRules" label-width="80px">
        <el-form-item label="线边仓" prop="storehouse">
          <StoreSelect
            v-model="settingForm.storehouse"
            :key="`storehouse`"
            :line="form.lineCode"
            :section="form.sectionCode"
            @change="storeChange"
            placeholder="请选择线边仓段"
            title="选择线边仓"
          ></StoreSelect>
        </el-form-item>
        <el-form-item label="库位" prop="bin">
          <BinSelect
            v-model="settingForm.bin"
            :key="`bin`"
            :parent="settingForm.storehouse"
            placeholder="请选择库位"
          ></BinSelect>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitSetting">确 定</el-button>
          <el-button @click="cancelSetting">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="warehouse">
import {
  getInStorehouse,
  addInStorehouse,
  confirmInStorehouse,
  updateInStorehouse,
} from "@/api/warehouse/inStorehouse";
import {
  listWhStorehouseInDetail,
  delWhStorehouseInDetail,
} from "@/api/warehouse/WhStorehouseInDetail";

import { reactive, toRefs, useAttrs, getCurrentInstance, computed, ref, onMounted } from "vue";
import matDialog from "./components/matDialog.vue";
import { deepClone } from "@/utils";
import { listStorehouse } from "@/api/storehouse/storehouse";

import { v4 as uuidv4 } from "uuid";
const attrs = useAttrs();
const { proxy } = getCurrentInstance();
const activeName = ref("first");
const { inout_storehouse } = proxy.useDict("inout_storehouse");
const operationTitle = ref("");
const storehouseList = ref([]);
const chioseList = ref([])
const isBatch = ref(false);
const refData = reactive({
  // 表单参数
  form: {},
  settingForm: {},
  searchParams: {
    batchNo: "",
    matName: "",
    matCode: "",
    matTypeName: "",
  },
  queryParams: {},
  // 表单校验
  rules: {},
  settingRules: {
    workshopCode: [{ required: true, message: "工段不能为空", trigger: "change" }],
    productLine: [{ required: true, message: "产线不能为空", trigger: "change" }],
    storehouse: [{ required: true, message: "线边仓不能为空", trigger: "change" }],
    bin: [{ required: true, message: "库位不能为空", trigger: "change" }],
  },
});
const { form, rules, settingForm, searchParams, queryParams, settingRules } = toRefs(refData);
const emit = defineEmits(["close", "setActions", "setIsActionTop"]);
const formRef = ref("formRef");
const tableForm = ref("tableForm");
const show = ref(false);
const editAble = ref(false);
const allTableData = ref([]);
const binEditAble = ref(false);
const actions = ref([
  {
    text: "取 消",
    theme: "",
    handle: () => {
      cancel();
    },
  },
  {
    text: "确 定",
    theme: "primary",
    handle: () => {
      submitForm();
    },
    loading: false,
  },
]);

/** 搜索按钮操作 */
function handleQuery() {
  filterSubTable();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value = {};
  filterSubTable();
}
function filterSubTable() {
  queryParams.value = { ...searchParams.value };
}

async function getStorehouseList() {
  if (form.value.lineCode || form.value.sectionCode) {
    await listStorehouse({
      lineCode: form.value.lineCode,
      sectionCode: form.value.sectionCode,
      pageSize: 10000,
      pageNum: 1,
    }).then((res) => {
      storehouseList.value = res.rows;
    });
  } else {
    storehouseList.value = [];
  }
}

const whStorehouseInDetailList = computed(() => {
  const result = [];
  allTableData.value.forEach((el) => {
    if (
      ((queryParams.value.orderCode && el.orderCode === queryParams.value.orderCode) ||
        !queryParams.value.orderCode) &&
      ((queryParams.value.productName && el.productName.includes(queryParams.value.productName)) ||
        !queryParams.value.productName) &&
      ((queryParams.value.matName && el.matName.includes(queryParams.value.matName)) ||
        !queryParams.value.matName)
    ) {
      result.push(el);
    }
  });
  return result;
});

function handleInputChange(val, scope, field) {
  if (field === "binCode") {
    allTableData.value[scope.$index][field] = val.binCode;
    allTableData.value[scope.$index].binName = val.binName;
  } else {
    allTableData.value[scope.$index][field] = val;
  }
}

// 取消按钮
function cancel() {
  emit("close");
}

// 表单重置
function reset() {
  form.value = {
    inOrderType: "0",
    inOrderCode: "",
    inOrderName: "",
    erpOrderCode: "",
    factoryCode: "",
    workshopCode: "",
    lineCode: "",
    sectionCode: "",
    deliveryPerson: "",
    comeTime: proxy.parseTime(new Date(), "{y}-{m}-{d} {h}:{i}:{s}"),
    remark: "",
    whStorehouseInDetailList: [],
  };
  formRef.value.resetFields();
  queryParams.value = {};
  allTableData.value = [];
}
const showSetting = ref(false);
const settingDialog = ref("settingDialog");
const batchSetting = () => {
  if (!whStorehouseInDetailList.value.length) {
    proxy.$modal.msgError("请先添加物料");
    return;
  }
  showSetting.value = true;
};
function toolChange() {
  settingForm.value.storehouse = "";
  settingForm.value.bin = "";
  allTableData.value.map((el) => {
    el.storehouseCode = "";
    el.storehouseName = "";
    el.binCode = "";
    el.binName = "";
  });
  getStorehouseList(form.value.lineCode, form.value.sectionCode);
}
// function orderChange() {
//   allTableData.value = [];
// }

function storeChange() {
  settingForm.value.bin = "";
}
function tableStoreChange(val, scope) {
  scope.row.binCode = "";
  allTableData.value[scope.$index].storehouseCode = val.storehouseCode;
  allTableData.value[scope.$index].storehouseName = val.storehouseName;
}
function cancelSetting() {
  showSetting.value = false;
}
function submitSetting() {
  settingDialog.value.validate((valid) => {
    if (valid) {
      whStorehouseInDetailList.value.forEach((el) => {
        el.storehouseCode = settingForm.value.storehouse;
        el.binCode = settingForm.value.bin;
      });
      showSetting.value = false;
    }
  });
}
/** 修改按钮操作 */
function getDetail(id) {
  getInStorehouse(id).then((response) => {
    form.value = response.data;
    if (operationTitle.value === "确认入仓" && !form.value.inTime) {
      if (isBatch.value) {
        form.value.inTime = proxy.parseTime(new Date(), "{y}-{m}-{d} {h}:{i}:{s}");
      } else {
        form.value.inTime = form.value.comeTime;
      }
    }
    if (operationTitle.value === "确认入仓" || operationTitle.value === "编辑来料入仓") {
      getStorehouseList(form.value.lineCode, form.value.sectionCode);
    }
    // if (proxy.checkPermi(["warehouse:WhStorehouseInDetail:list"])) {
      getListWhStorehouseInDetail(response.data.inOrderCode);
    // }
  });
}

/** 提交按钮 */
function submitForm() {
  if (operationTitle.value == "确认入仓") {
    proxy.$modal.confirm("是否提交确认入仓？").then(() => {
      formRef.value.validate((valid) => {
        if (valid) {
          resetQuery();
          if (allTableData.value.length) {
            tableForm.value.validate((result) => {
              if (result) {
                form.value.whStorehouseInDetailList = allTableData.value;
                if (isBatch.value) {
                  form.value.ids = form.value.id;
                  const params = deepClone(form.value);
                  delete params.id;
                  updateInStorehouse(params)
                    .then(() => {
                      confirmInStorehouse({ ids: form.value.id }).then(() => {
                        proxy.$modal.msgSuccess("提交成功");
                        cancel();
                      });
                    })
                    .catch(() => {
                      proxy.$modal.msgError("提交失败，请重试");
                    });
                } else {
                  addInStorehouse(form.value)
                    .then(() => {
                      confirmInStorehouse({ ids: [form.value.id] }).then(() => {
                        proxy.$modal.msgSuccess("提交成功");
                        cancel();
                      });
                    })
                    .catch(() => {
                      proxy.$modal.msgError("提交失败，请重试");
                    });
                }
              }
            });
          } else {
            proxy.$modal.msgError("请添加物料");
          }
        }
      });
    });
  } else {
    formRef.value.validate((valid) => {
      if (valid) {
        resetQuery();
        if (allTableData.value.length) {
          tableForm.value.validate((result) => {
            if (result) {
              proxy.$modal.confirm("是否提交来料入仓？").then(() => {
                form.value.whStorehouseInDetailList = allTableData.value;
                addInStorehouse(form.value).then((response) => {
                  proxy.$modal.msgSuccess("提交成功");
                  emit("close", response.data);
                });
              });
            }
          });
        } else {
          proxy.$modal.msgError("请添加物料");
        }
      }
    });
  }
}

/** 来料入仓明细序号 */
function rowWhStorehouseInDetailIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}
/** 来料入仓明细添加按钮操作 */
function handleAddWhStorehouseInDetail() {
  formRef.value.validate((valid) => {
    if (valid) {
      show.value = true;
      if(allTableData.value&& allTableData.value.length){
        chioseList.value = []
        allTableData.value.forEach(item=>{
          chioseList.value.push({
            orderCode:item.orderCode,
            prodName:item.productName,
            prodCode:item.productCode,
            bomCode:item.matCode,
            bomName:item.matName,
            unit:item.unit,
            packages:item.spec,
            number:item.receiveNumber,
          })
        })
      }
    }
  });
}
function handleChange(val) {
  if (val.length) {
    let chioseID = []
    if(allTableData.value && allTableData.value.length) {
      allTableData.value.forEach(i=>{
        chioseID.push(i.orderCode+i.productCode+i.matCode)
      })
    }
    val.forEach((el) => {
      let obj = {};
      obj.randomId = uuidv4();
      obj.orderCode = el.orderCode;
      obj.productName = el.prodName;
      obj.productCode = el.prodCode;
      obj.matCode = el.bomCode;
      obj.matName = el.bomName;
      obj.factory = "";
      obj.batchNo = "";
      obj.unit = el.unit;
      obj.spec = el.packages;
      obj.receiveNumber = el.number;
      obj.storehouseCode = form.value.storehouseCode;
      obj.storehouseInCode = form.value.inOrderCode;
      obj.binCode = "";
      obj.remark = "";
      const code = obj.orderCode+obj.productCode+obj.matCode;
      if(!chioseID.includes(code)){
        allTableData.value.push(obj);
      }
    });
  }
}
/** 来料入仓明细删除按钮操作 */
function handleDeleteWhStorehouseInDetail(row, index) {
  proxy.$modal
    .confirm("是否确认移除序号为 " + (index + 1) + " 的数据项？")
    .then(() => {
      if (row.id) {
        delWhStorehouseInDetail(row.id).then(() => {
          allTableData.value = allTableData.value.filter((item) => {
            return item.id !== row.id;
          });
          this.$modal.msgSuccess("移除成功");
        });
      } else {
        allTableData.value.forEach((el, i) => {
          if (el.randomId && el.randomId === row.randomId) {
            allTableData.value.splice(i, 1);
          }
        });
        this.$modal.msgSuccess("移除成功");
      }
    })
    .catch(() => {});
}

function getListWhStorehouseInDetail(code) {
  listWhStorehouseInDetail({ pageSize: 10000, pageNum: 1, storehouseInCode: code }).then((res) => {
    if (isBatch.value) {
      allTableData.value.push(...res.rows);
    } else {
      allTableData.value = res.rows;
    }
  });
}

onMounted(() => {
  reset();
  const { data, title, code } = attrs;
  binEditAble.value = true;
  operationTitle.value = title;
  if (title === "确认入仓") {
    editAble.value = false;
    actions.value = [
      {
        text: "取 消",
        theme: "",
        handle: () => {
          cancel();
        },
      },
      {
        text: "确 定",
        theme: "primary",
        handle: () => {
          submitForm();
        },
        loading: false,
      },
    ];
  } else if (title === "物料入仓详情") {
    editAble.value = false;
    binEditAble.value = false;
    actions.value = [];
  } else {
    rules.value = {
      inOrderType: [{ required: true, message: "入仓类型不能为空", trigger: "change" }],
      inOrderCode: [{ required: true, message: "入仓单编号不能为空", trigger: ["blur", "change"] }],
      inOrderName: [{ required: true, message: "入仓单名称不能为空", trigger: ["blur", "change"] }],
      factoryCode: [{ required: true, message: "工厂不能为空", trigger: "change" }],
      workshopCode: [{ required: true, message: "工段不能为空", trigger: "change" }],
      lineCode: [{ required: true, message: "产线不能为空", trigger: "change" }],
      storehouseCode: [{ required: true, message: "仓库不能为空", trigger: "blur" }],
      comeTime: [{ required: true, message: "来料时间不能为空", trigger: "blur" }],
    };
    editAble.value = true;
  }
  emit("setActions", actions.value);
  if (code) {
    isBatch.value = true;
    const orderCodes = [];
    const erpOrderCodes = [];
    const inOrderNames = [];
    const deliveryPersons = [];
    const comeTimes = [];
    data.forEach((el) => {
      orderCodes.push(el.inOrderCode);
      inOrderNames.push(el.inOrderName);
      erpOrderCodes.push(el.erpOrderCode);
      deliveryPersons.push(el.deliveryPerson);
      comeTimes.push(el.comeTime);
      // if (proxy.checkPermi(["warehouse:WhStorehouseInDetail:list"])) {
        getListWhStorehouseInDetail(el.inOrderCode);
      // }
    });

    form.value = data[0];
    form.value.id = code;
    form.value.inOrderCode = orderCodes.join(",");
    form.value.erpOrderCode = erpOrderCodes.join(",");
    form.value.inOrderName = inOrderNames.join(",");
    form.value.deliveryPerson = deliveryPersons.join(",");
    form.value.comeTime = comeTimes.join(",");
    form.value.inTime = proxy.parseTime(new Date(), "{y}-{m}-{d} {h}:{i}:{s}");
    getStorehouseList(form.value.lineCode, form.value.sectionCode);
  } else {
    isBatch.value = false;
    if (data) {
      getDetail(data.id);
    }
  }
});
</script>

<style lang="scss">
.form-text {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
